/**
 * \file MemoryPoolManager.h
 * \brief MemoryPoolManager definition class
 * \author Edouard ROGE
 * \date 06 august 2012
 */

#ifndef _MEMORYPOOLMANAGER_
#define _MEMORYPOOLMANAGER_

#include <stdlib.h>
#include "Core/Pattern/Singleton.h"
#include "IMemoryManager.h"
#include "MemoryPool.h"


namespace Core
{
	namespace Memory
	{
		/**
		 * \class MemoryPoolManager
		 * \brief MemoryPoolManager manages the amount of allocated memory, track memory leaks, speed up allocation and deallocation. It is implicit called each time a HeapObject is allocated and freed
		 */
		class CORE_LINUX MemoryPoolManager : public Singleton<MemoryPoolManager>, public IMemoryManager
		{
		public:
			/**
			 * \fn MemoryPoolManager();
			 * \brief Default constructor
			 */
			MemoryPoolManager();

			/**
			 * \fn virtual ~MemoryPoolManager();
			 * \brief Destructor
			 */
			virtual ~MemoryPoolManager();

			/**
			 * \fn void * Allocate(size_t _iSize);
			 * \param _iSize size of needed allocated memory
			 * \return pointer to the allocated memory, if the pool is full, return 'normal' allocated memory
			 * \brief allocate memory
			 */
			void * Allocate(size_t _iSize);

			/**
			 * \fn void Free(void * _ptr);
			 * \param _ptr address of the pointer to free
			 * \brief free memory
			 */
			void Free(void * _ptr);

			/**
			 * \fn std::vector<void*> GetMemoryLeaks() const;
			 * \return vector with all memory leaks
			 * \brief Find memory leaks
			 */
			std::vector<void*> GetMemoryLeaks() const;

			/**
			 * \fn void CheckLeaks(bool _bClearLeaks=true);
			 * \param _bClearLeaks if true clear memory leaks found
			 * \brief Find and display memory leaks
			 */
			void CheckLeaks(bool _bClearLeaks = true);

		private:

			/** vector of memory pool */
			std::vector<MemoryPool> m_MemoryPools;
		};
	}
}

#endif // _MEMORYPOOLMANAGER_
